home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH09 / EX9_1.ASM next >
Encoding:
Assembly Source File  |  1993-09-25  |  2.0 KB  |  88 lines

  1.  
  2. dseg        segment    para public 'data'
  3.  
  4. I        word    0
  5. J        word    0
  6. K        word    0
  7.  
  8. dseg        ends
  9.  
  10.  
  11. cseg        segment    para public 'code'
  12.         assume    cs:cseg, ds:dseg
  13.  
  14.  
  15. ; This program is useful for debugging purposes only!
  16. ; The intent is to execute this code from inside CodeView.
  17. ;
  18. ; This program is riddled with bugs.  The bugs are very obvious in
  19. ; this short code sequence, within a larger program these bugs might
  20. ; not be quite so obvious.
  21.  
  22. Main        proc
  23.         mov    ax, dseg
  24.         mov    ds, ax
  25.         mov    es, ax
  26.  
  27. ; The following loop increments I until it reaches 10
  28.  
  29. ForILoop:    inc    I
  30.         cmp    I, 10
  31.         jb    ForILoop
  32.  
  33. ; This loop is supposed to do the same thing as the loop above, but we
  34. ; forgot to reinitialize I back to zero.  What happens?
  35.  
  36. ForILoop2:    inc    I
  37.         cmp    I, 10
  38.         jb    ForILoop2
  39.  
  40.  
  41. ; The following loop, once again, attempts to do the same thing as the first
  42. ; for loop above.  However, this time we remembered to reinitialize I.  Alas,
  43. ; there is another problem with this code, a typo which the assembler cannot
  44. ; catch.
  45.  
  46.         mov    I, 0
  47. ForILoop3:    inc    I
  48.         cmp    I, 10
  49.         jb    ForILoop    ;<<<-- Whoops! Typo.
  50.  
  51. ; The following loop adds I to J until J reaches 100.  Unfortunately,
  52. ; the author of this code must have been confused and thought that AX
  53. ; contained the sum accumulating in J.  It compares AX against 100 when
  54. ; it should really be comparing J against 100.
  55.  
  56. WhileJLoop:    mov    ax, I
  57.         add    J, ax
  58.         cmp    ax, 100        ;This is a bug!
  59.         jb    WhileJLoop
  60.  
  61.  
  62.  
  63.  
  64.         mov    ah, 4ch        ;Quit to CodeView/DOS.
  65.         int    21h
  66. Main        endp
  67.  
  68. cseg            ends
  69.  
  70.  
  71.  
  72. ; Allocate a reasonable amount of space for the stack (8k).
  73. ; Note: if you use the pattern matching package you should set up a
  74. ;    somewhat larger stack.
  75.  
  76. sseg        segment    para stack 'stack'
  77. stk        db    1024 dup ("stack   ")
  78. sseg        ends
  79.  
  80.  
  81. ; zzzzzzseg must be the last segment that gets loaded into memory!
  82. ; This is where the heap begins.
  83.  
  84. zzzzzzseg    segment    para public 'zzzzzz'
  85. LastBytes    db    16 dup (?)
  86. zzzzzzseg    ends
  87.         end    Main
  88.